package com.yumis.service.modules.user.controller;

import com.yumis.service.common.enums.HttpState;
import com.yumis.service.common.vo.Response;
import com.yumis.service.model.pojo.Shop;
import com.yumis.service.model.pojo.UserCar;
import com.yumis.service.modules.user.service.UserCarService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("usercar")
public class UserCarController {
    @Autowired
    private UserCarService userCarService;

    /**
     * 新增
     * @param userCar
     * @return
     */
    @PostMapping("addUserCar")
    public ResponseEntity<Response> addUserCar(@Valid UserCar userCar){
        userCarService.addUserCar(userCar);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }
    /**
     * 根据id删除
     * @param id
     * @return
     */
    @PostMapping("deleteUserCarById")
    public ResponseEntity<Response> deleteUserCarById(@RequestParam("id") Long id){
        userCarService.deleteUserCarById(id);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }
    /**
     * 根据id查询
     * @param id
     * @return
     */
    @PostMapping("queryUserCarById")
    public ResponseEntity<Response> queryUserCarById(@RequestParam("id") Long id){
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK,userCarService.queryUserCarById(id)));
    }

    /**
     * 修改
     * @param userCar
     * @return
     */
    @PostMapping("updateShop")
    public ResponseEntity<Response> updateUserCar(@Valid UserCar userCar){
        userCarService.updateUserCar(userCar);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }
}
